package com.developer.platform.controller.login;

import com.developer.platform.application.query.LoginManager;
import com.developer.platform.application.query.dto.CurrUserDto;
import com.developer.platform.application.query.dto.LoginQuery;
import com.veeker.log.annotations.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.validation.Valid;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：qiaoliang
 * @date ：2020-11-09
 */
@Api(tags = "登录管理")
@Validated
@RestController
public class LoginController {

    private final LoginManager loginManager;

    public LoginController(LoginManager loginManager) {
        this.loginManager = loginManager;
    }

    @ApiOperation(value = "登录")
    @Log(businessType = "登录管理",discription = "登录")
    @PostMapping(value = "/login")
    public ResponseEntity<String> login(@Valid @RequestBody LoginQuery login) {
        return ResponseEntity.status(HttpStatus.CREATED).body(loginManager.login(login));
    }

    @Log(businessType = "登录管理",discription = "查询当前用户信息")
    @ApiOperation(value = "查询当前用户信息")
    @GetMapping("/info")
    public ResponseEntity<CurrUserDto> currUser(){
        return ResponseEntity.ok(loginManager.currUser());
    }

}
